﻿package cn.poco.pepsi.util.xmlpared;

import java.io.InputStream;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;
import cn.poco.pepsi.bean.ActivityImage;

public class ActivityImageXmlparse {

	private static ArrayList<ActivityImage> images = null;
	private static  ActivityImage ctivityImagebean = null;
	
	public static ArrayList<ActivityImage> getXml(InputStream inSteam) throws Exception{
		
		XmlPullParser xmpparse = Xml.newPullParser();   //得到解释器
		xmpparse.setInput(inSteam, "UTF-8");           //设置解释流
		int code = xmpparse.getEventType();            //得到节点信息
		String total = null;
		while(code != XmlPullParser.END_DOCUMENT){
			switch (code) {
			case XmlPullParser.START_DOCUMENT:
				//初始化
				images = new ArrayList<ActivityImage>();
				break;
			case XmlPullParser.START_TAG:
				if("total".equals(xmpparse.getName())){
					total = xmpparse.nextText();
				}
				if("photo".equals(xmpparse.getName())){
					ctivityImagebean = new ActivityImage();
					ctivityImagebean.setTotal(Integer.parseInt(total));
				}
				if(ctivityImagebean!=null){
					if("title".equals(xmpparse.getName())){
						String title = xmpparse.nextText();
						ctivityImagebean.setTitle(title);
					}
					if("url".equals(xmpparse.getName())){
						String url = xmpparse.nextText();
						ctivityImagebean.setUrl(url);
					}
				}	
				break;
			case XmlPullParser.END_TAG:
				if("photo".equals(xmpparse.getName())){
					images.add(ctivityImagebean);
					ctivityImagebean = null;
				}
				break;
			}
			code = xmpparse.next();
		}
		inSteam.close();
		return images;
	} 
}
